import scrapy


class CarHomeSpider(scrapy.Spider):
    name = "car_home"
    allowed_domains = ["www.autohome.com.cn"]
    start_urls = ["https://www.autohome.com.cn/price/brandid_15?pvareaid=104399"]

    def parse(self, response):
        print('===============================================')
        # print(response.text)

        name_list = response.xpath(
            "//div[@class='tw-mb-[30px]']//a[@class='tw-text-hover tw-mr-2 tw-min-w-0 tw-text-[18px] tw-font-[500]']/text()")

        price_list = response.xpath(
            "//div[@class='tw-mb-[30px]']//a[@class='tw-text-[16px] tw-font-[500] !tw-text-[#f60]']/text()")

        for i in range(len(name_list)):
            print('汽车名称 ：', name_list[i].extract())
            print('汽车价格 ：', price_list[i].extract())
            print('===========================')
